package com.hoyue.classroom.service.impl;

import com.hoyue.classroom.bean.Group;
import com.hoyue.classroom.dao.GroupMapper;
import com.hoyue.classroom.service.GroupService;
import com.hoyue.common.utils.DateUtils;
import com.hoyue.system.bean.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author 空白
 * @version 1.0
 * Create by 2019/08/31 10:52
 */
@Service
public class GroupServiceImpl implements GroupService {

    DateUtils dateUtils;

    @Resource
    GroupMapper groupMapper;

    @Override
    public int createGroup(String name, Integer userId, Integer courseId) {
        // 获取当前时间
        Date time = dateUtils.getDateTime();
        Group group = new Group(courseId, name, userId, time, time);
        return groupMapper.createGroup(group);
    }

    @Override
    public Group getGroup(Integer groupId) {
        return groupMapper.getGroup(groupId);
    }

    @Override
    public int updateGroup(Integer groupId, String name) {
        // 查询课程信息
        Group group = groupMapper.getGroup(groupId);
        // 修改信息
        group.setName(name);
        group.setUpdateTime(DateUtils.getDateTime());
        // 更新信息
        return groupMapper.updateGroup(group);
    }

    @Override
    public List<Group> listGroup(Integer courseId) {
        return groupMapper.listGroup(courseId);
    }

    @Override
    public List<User> listGroupMember(Integer groupId) {
        return groupMapper.listGroupMember(groupId);
    }
}
